package com.omnisyr.textrebuilder.common;

import com.omnisyr.textrebuilder.util.structure.ColorList;

public class ColorPointCloud {

	private int[][][] denseList;
	private ColorList points = new ColorList();

	public ColorPointCloud add(Color color) {

		this.points.add(color);
		return this;

	}

	public ColorPointCloud remove(int r, int g, int b) {

		this.points.remove(r, g, b);
		return this;

	}

	public int count(int r, int g, int b, boolean mode) {

		return this.points.count(r, g, b, 0, mode);

	}

	public int buildDenseList(boolean mode) {

		int count = 0;
		long add = 0;

		this.denseList = new int[256][256][256];

		for (int i = 0; i < 256; i++) {

			for (int j = 0; j < 256; j++) {

				for (int k = 0; k < 256; k++) {

					int dense = this.points.count(i, j, k, 2, mode);

					if (dense == 0) {

						continue;

					}

					this.denseList[i][j][k] = dense;

					count++;
					add += dense;

				}

			}

		}

		System.err.println("Pixel Amount: " + add);
		System.err.println("Color Amount: " + count);

		return (int) (add / count);

	}

	public int dense(int r, int g, int b) {

		return this.denseList[r][g][b];

	}

}
